package com.study.quiz.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.study.quiz.pojo.Question;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import java.util.List;

/**
 * @author CJunGod
 * @create 2020-03-05 11:01
 **/
public interface QuestionMapper extends BaseMapper<Question> {

    @Select("select * from QUESTION where tag regexp #{tag} Order By GMT_CREATE desc")
    List<Question> findList(String tag);

    @Update("update QUESTION set VIEW_COUNT=VIEW_COUNT +1, GMT_MODIFIED=#{gmtModified} where ID = #{questionId}")
    Integer updateView(@Param("questionId") Integer questionId, @Param("gmtModified") Long gmtModified);

    @Update("update QUESTION set COMMENT_COUNT=COMMENT_COUNT +1, GMT_MODIFIED=#{gmtModified} where ID = #{questionId}")
    Integer updateComment(@Param("questionId") Integer questionId, @Param("gmtModified") Long gmtModified);

    @Select("select * from QUESTION where id != #{id} and tag regexp #{tag}")
    List<Question> findByTag(Question question);

    @Select("select COUNT(1) from QUESTION where tag regexp #{tag}")
    Integer findBySearch(String tag);
}
